class MaterialsController < ApplicationController

     def index
        if authorize
            @listing = CourseMaterial.find_all_materials
            if session[:loginrole] == "Admin"
                @dashboard = "Go to Gradebook"
            end
        end
     end

     def authorize 
        unless session[:loggedin] == true
        flash[:notice] = "Please log in" 
            redirect_to :controller => :login, :action => :index 
            return false
        end
        return true 
     end 
     
     def add_material
        #recs = CourseMaterial.count
        #CourseMaterial.create(:title => params[:title], :document_url => 'some url', :document => params[:uploaded_document])
        @course_material = CourseMaterial.new(params[:course_material])
        @course_material.save
        @course_material.update_attribute(:doc_type, 3)
        redirect_to :controller => :materials, :action => :index 
     end

     def course_material
      @course_material = CourseMaterial.find(params[:id])
      send_data(@course_material.document,
                :filename => @course_material.filename,
                :type => @course_material.content_type,
                :disposition => "inline")
    end
  
end
